package com.shujia.core

import org.apache.spark.rdd.RDD
import org.apache.spark.{SparkConf, SparkContext}

object Code37Object {
  def main(args: Array[String]): Unit = {
    val sc = new SparkContext(new SparkConf().setMaster("local").setAppName("object"))

    val data: RDD[String] = sc.textFile("spark_code/data/score.txt")

    data
      .map {
        line => {
          val splitRes: Array[String] = line.split(",")
          ScoreObj(splitRes(0), splitRes(1), splitRes(2).toInt)
        }
      }.groupBy(_.id)
      .mapValues(_.map(x => x.score).sum)
      .foreach(println)

  }
}

case class ScoreObj(id: String, courseID: String, score: Int)
